﻿using ShortcutMenu.Render;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace ShortcutMenu.Manager
{
    public class ReaderManager : ManagerBase
    {
        Dictionary<Type, RenderBase> _renderBase;

        //当前显示的渲染类
        private RenderBase _curDisplayRander;

        public ReaderManager()
        {
            var ass = Assembly.GetAssembly(this.GetType())!.GetTypes();
            var mainWindow = MenuApplication.GetMainWondw();
            _renderBase = Reflection.Create<RenderBase>(ass, mainWindow);
        }

        public override void initialize()
        { }

        public T GetReader<T>() where T : RenderBase
        {
            return (T)_renderBase[typeof(T)]!;
        }

        /// <summary>
        /// 显示指定窗口
        /// </summary>
        public void ShowWindow<T>() where T : RenderBase
        {
            var reader = GetReader<T>();
            _curDisplayRander = reader;
            reader.Show();
        }

        /// <summary>
        /// 隐藏当前窗口
        /// </summary>
        public void HideCurWindow()
        {
            if (_curDisplayRander != null)
            {
                _curDisplayRander.Hide();
            }
        }

    }
}
